package api

import (
	"github.com/gin-gonic/gin"
	"go-learn/dao"
	demo2 "go-learn/model/request"
	"go-learn/model/response"
)

func HSet(c *gin.Context) {
	var data demo2.RedisHash
	_ = c.ShouldBind(&data)
	err := dao.HSet(data.Key, data.Field, data.Value)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func HGet(c *gin.Context) {
	var data demo2.RedisHash
	_ = c.ShouldBind(&data)
	value, err := dao.HGet(data.Key, data.Field)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(value, c)
}
func HMSet(c *gin.Context) {
	var data demo2.RedisHash
	_ = c.ShouldBind(&data)
	err := dao.HMSet(data.Key, data.FieldMap)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func HMGet(c *gin.Context) {
	var data demo2.RedisHash
	_ = c.ShouldBind(&data)
	value, err := dao.HMGet(data.Key, data.Fields...)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(value, c)
}
func HDel(c *gin.Context) {
	var data demo2.RedisDel
	_ = c.ShouldBind(&data)
	err := dao.HDel(data.Key, data.Fields...)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
